import React, { useState } from 'react'
import './indexExam.scss'
import AnswerSheet from './answerSheet'
import QuestionShowList from './questionShowList'
import { useLocation } from 'react-router-dom'
import { useEffect } from 'react'
import { http } from '../utils'


function Exam () {

  const { state: { T, D } } = useLocation()

  const [test, setTest] = useState(
    {
      "id": 23,
      "name": "第一份看起来像样子的试卷",
      "description": "这是关于《第一份看起来像样子的试卷》的描述",
      "status": 1,
      "subject_name": "小学数学",
      "total_score": 130,
      "test_time": 120,
      "start_time": "2022-09-04 09:25:46",
      "end_time": "2022-09-04 09:25:47",
      "judge_question_list": [{
        "answer": true,
        "description": null,
        "score": 5,
        "question_number": 1,
        "question_stem": "1+1=2"
      }, {
        "answer": false,
        "description": "1+2=3啊混蛋",
        "score": 5,
        "question_number": 2,
        "question_stem": "1+2=2"
      }],
      "gap_filling_question_list": [{
        "description": "2+2不等于4还能等于什么呢",
        "answer": ["4"],
        "score": 5,
        "question_number": 1,
        "question_stem": "2+2=_"
      }, {
        "description": "没错是爷爷",
        "answer": ["爷爷"],
        "score": 5,
        "question_number": 2,
        "question_stem": "爸爸的爸爸叫__"
      }],
      "single_select_question_list": [{
        "description": null,
        "item": ["A.纯路人", "B.小黑子", "C.ikun"],
        "answer": [0],
        "score": 10,
        "question_number": 1,
        "question_stem": "坤坤的真粉丝一般自称什么"
      }, {
        "description": null,
        "item": ["A.英文单词Control的缩写", "B.windows电脑键盘上的按键", "C.唱跳rap篮球"],
        "answer": [2],
        "score": 10,
        "question_number": 2,
        "question_stem": "请解释Ctrl的含义"
      }, {
        "description": null,
        "item": ["A.速度删除", "B.外国友人的名字", "C.大妈"],
        "answer": [0],
        "score": 10,
        "question_number": 3,
        "question_stem": "苏珊指的是什么"
      }, {
        "description": null,
        "item": ["A.绿色的尸体会散发出冷气", "B.绿色的僵尸害怕寒冷", "C.律师函"],
        "answer": [2],
        "score": 10,
        "question_number": 4,
        "question_stem": "绿尸寒指的是什么"
      }, {
        "description": null,
        "item": ["A.1,1", "B.2,2", "C.3,3", "D.1.5,0.5"],
        "answer": [0, 3],
        "score": 10,
        "question_number": 5,
        "question_stem": "_+_=2"
      }, {
        "description": null,
        "item": ["A.你", "B.我", "C.她", "D.他"],
        "answer": [2, 3],
        "score": 10,
        "question_number": 6,
        "question_stem": "你是谁"
      }],
      "multipart_select_question_list": [],
      "short_answer_question_list": [{
        "description": null,
        "answer": "答案就是,我也不懂为什么1+1会得出2",
        "score": 50,
        "question_number": 1,
        "question_stem": "请简述1+1=2的原因"
      }]
    }
  )

  //
  async function getTest (id) {
    const res = await http.get(`/base_server/api/v1/pub/paper/test/find_by_id${'?paper_id='}${id}`)
    setTest(res.data)
  }
  useEffect(() => {
    getTest(T.selectTestId)
  }, [])// eslint-disable-line

  return (
    <div className='exam-index'>
      <AnswerSheet
        test={test}
      >
      </AnswerSheet>
      <div className='title-content'>
        <div className='title-box'>
          <QuestionShowList
            test={test}
            id={D.id.id}
          >
          </QuestionShowList>
        </div>
      </div>

    </div>


  )
}

export default Exam